package com.ems.sys.service.impl;

import com.ems.sys.dao.EmsQuitMapper;
import com.ems.sys.pojo.EmsQuit;
import com.ems.sys.service.EmsQuitService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:EmsQuit业务层接口实现类
 * @Date 2019/6/14 0:16
 *****/
@Service
public class EmsQuitServiceImpl implements EmsQuitService {

    @Autowired
    private EmsQuitMapper emsQuitMapper;


    /**
     * EmsQuit条件+分页查询
     * @param emsQuit 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public PageInfo<EmsQuit> findPage(EmsQuit emsQuit, int page, int size){
        //分页
        PageHelper.startPage(page,size);
        //搜索条件构建
        Example example = createExample(emsQuit);
        //执行搜索
        return new PageInfo<EmsQuit>(emsQuitMapper.selectByExample(example));
    }

    /**
     * EmsQuit分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo<EmsQuit> findPage(int page, int size){
        //静态分页
        PageHelper.startPage(page,size);
        //分页查询
        return new PageInfo<EmsQuit>(emsQuitMapper.selectAll());
    }

    /**
     * EmsQuit条件查询
     * @param emsQuit
     * @return
     */
    @Override
    public List<EmsQuit> findList(EmsQuit emsQuit){
        //构建查询条件
        Example example = createExample(emsQuit);
        //根据构建的条件查询数据
        return emsQuitMapper.selectByExample(example);
    }


    /**
     * EmsQuit构建查询对象
     * @param emsQuit
     * @return
     */
    public Example createExample(EmsQuit emsQuit){
        Example example=new Example(EmsQuit.class);
        Example.Criteria criteria = example.createCriteria();
        if(emsQuit!=null){
            //
            if(!StringUtils.isEmpty(emsQuit.getEId())){
                    criteria.andEqualTo("eId",emsQuit.getEId());
            }
            //
            if(!StringUtils.isEmpty(emsQuit.getEName())){
                    criteria.andEqualTo("eName",emsQuit.getEName());
            }
            //
            if(!StringUtils.isEmpty(emsQuit.getQuitDate())){
                    criteria.andEqualTo("quitDate",emsQuit.getQuitDate());
            }
            //
            if(!StringUtils.isEmpty(emsQuit.getQuitReason())){
                    criteria.andEqualTo("quitReason",emsQuit.getQuitReason());
            }
            //
            if(!StringUtils.isEmpty(emsQuit.getQuitStatus())){
                    criteria.andEqualTo("quitStatus",emsQuit.getQuitStatus());
            }
            //
            if(!StringUtils.isEmpty(emsQuit.getRemarks())){
                    criteria.andEqualTo("remarks",emsQuit.getRemarks());
            }
        }
        return example;
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(String id){
        emsQuitMapper.deleteByPrimaryKey(id);
    }

    /**
     * 修改EmsQuit
     * @param emsQuit
     */
    @Override
    public void update(EmsQuit emsQuit){
        emsQuitMapper.updateByPrimaryKey(emsQuit);
    }

    /**
     * 增加EmsQuit
     * @param emsQuit
     */
    @Override
    public void add(EmsQuit emsQuit){
        emsQuitMapper.insert(emsQuit);
    }

    /**
     * 根据ID查询EmsQuit
     * @param id
     * @return
     */
    @Override
    public EmsQuit findById(String id){
        return  emsQuitMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询EmsQuit全部数据
     * @return
     */
    @Override
    public List<EmsQuit> findAll() {
        return emsQuitMapper.selectAll();
    }
}
